<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>做试卷</title>
    <link href="https://cdn.bootcss.com/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
    <div class="container">
        <div class="row">
            <div class="col-md-2"></div>
            <div class="col-md-8">
                <form class="form-horizontal" id="answerForm" method="post" >
                    <input type="hidden" name="testPaperId" value="${tp.testPaperId}">
                    <#if tp??>
                        <div class="page-header" align="cneter">
                            <h1>${tp.testPaperName}</h1>
                            <small>考试时间: ${json.testTime}分钟</small>
                            <small>总分: ${json.totalScore}</small>
                        </div>

                        <#assign index=0>

                        <#if save.sgList?size != 0>
                            <div class="panel-title">
                                <h3>单项选择题 共${save.sgList?size}题,每题${json.sgScore}分</h3>
                            </div>
                            <#list save.sgList as sg>
                                <#assign index=index+1>
                                <div class="panel panel-default">
                                    <div class="panel panel-heading">
                                        <h1 class="panel-title">${index}.题目: ${sg.sgQuestion}</h1>
                                    </div>
                                    <div class="panel-body">
                                        <input type="radio" name="sg_${sg.sgQuestionId}" value="A">A  ${sg.choiceA}<br/>
                                        <input type="radio" name="sg_${sg.sgQuestionId}" value="B">B  ${sg.choiceB}<br/>
                                        <input type="radio" name="sg_${sg.sgQuestionId}" value="C">C  ${sg.choiceC}<br/>
                                        <input type="radio" name="sg_${sg.sgQuestionId}" value="D">D  ${sg.choiceD}<br/>
                                    </div>
                                </div>
                            </#list>
                        </#if>

                        <#if save.plList?size != 0>
                            <div class="panel-title">
                                <h3>多项选择题 共${save.plList?size}题,每题${json.plScore}分</h3>
                            </div>
                            <#list save.plList as pl>
                                <#assign index=index+1>
                                <div class="panel panel-default">
                                    <div class="panel panel-heading">
                                        <h1 class="panel-title">${index}.题目:${pl.plQuestion}</h1>
                                    </div>
                                    <div class="panel-body">
                                        <input class="" type="checkbox" name="pl_${pl.plQuestionId}" value="A">A  ${pl.choiceA}<br/>
                                        <input class="" type="checkbox" name="pl_${pl.plQuestionId}" value="B">B  ${pl.choiceB}<br/>
                                        <input class="" type="checkbox" name="pl_${pl.plQuestionId}" value="C">C  ${pl.choiceC}<br/>
                                        <input class="" type="checkbox" name="pl_${pl.plQuestionId}" value="D">D  ${pl.choiceD}<br/>
                                    </div>
                                </div>
                            </#list>
                        </#if>

                        <#if save.tofList?size != 0>
                            <div class="panel-title">
                                <h3>判断题 共${save.tofList?size}题,每题${json.tofScore}分</h3>
                            </div>
                            <#list save.tofList as tof>
                                <#assign index=index+1>
                                <div class="panel panel-default">
                                    <div class="panel panel-heading">
                                        <h1 class="panel-title">${index}.题目: ${tof.tofQuestion}</h1>
                                    </div>
                                    <div class="panel-body">
                                        <input type="radio" name="tof_${tof.tofQuestionId}" value="true">对<br/>
                                        <input type="radio" name="tof_${tof.tofQuestionId}" value="false">错<br/>
                                    </div>
                                </div>
                            </#list>
                        </#if>

                        <#if save.essayList?size != 0>
                            <div class="panel-title">
                                <h3>简答选择题 共${save.essayList?size}题,每题${json.essayScore}分</h3>
                            </div>
                            <#list save.essayList as el>
                                <#assign index=index+1>
                                <div class="panel panel-default">
                                    <div class="panel panel-heading">
                                        <h1 class="panel-title">${index}.题目: ${el.essayQuestion}</h1>
                                    </div>
                                    <div class="panel-body">
                                        <input class="form-control" type="text" name="essay_${el.essayQuestionId}"/>
                                    </div>
                                </div>
                            </#list>
                        </#if>

                        <#if save.fillList?size != 0>
                            <div class="panel-title">
                                <h3>填空题 共${save.fillList?size}题,每题${json.fillScore}分</h3>
                            </div>
                            <#assign index=index+1>
                            <#list save.fillList as fl>
                                <div class="panel panel-default">
                                    <div class="panel panel-heading">
                                        <h1 class="panel-title">${index}.题目: ${fl.fillQuestion}</h1>
                                    </div>
                                    <div class="panel-body">
                                        <input class="form-control" type="text" name="fill_${fl.fillQuestionId}"/>
                                    </div>
                                </div>
                            </#list>
                        </#if>
                        <div align="center">
                            <button class="btn-lg btn-success" onclick="test()">提交</button>
                        </div>
                    <#else>
                        <h1>未找到该试卷</h1>
                    </#if>
                </form>
            </div>
            <div class="col-md-2"></div>
        </div>
    </div>
</body>

<script src="/jquery-3.3.1/jquery-3.3.1.min.js"></script>
<script src="/bootstrap/js/bootstrap.min.js"></script>

<script>


    function test() {
        var answerJson = $("#answerForm").serializeArray();
        alert(answerJson);
        $.ajax({
            type:"post",
            url:"/student/testpaper/answer",
            dataType:"text",
            data:answerJson,
            success:function (data) {
                if(data=="success"){
                    alert("提交成功");
                    // 关闭当前页面
                    window.open("","_self").close();
                }else{
                    alert("提交失败");
                }
            }
        })
    }
</script>
</html>